import { ApiProperty } from "@nestjs/swagger"
import { Type } from "class-transformer"
import { IsEmail, IsInt, IsNotEmpty, IsOptional, MaxLength, MinLength } from "class-validator"
import { PaginatedDto } from "src/common/dto"

class UserDto {
    @ApiProperty({ example: 'coldpants', description: '用户名' })
    @IsNotEmpty({
        message: '用户名不能为空'
    })
    @MinLength(5)
    @MaxLength(16)
    username: string

    @ApiProperty({ example: 'coldpants@qq.com', description: '邮箱' })
    @IsNotEmpty({
        message: '邮箱不能为空'
    })
    @IsEmail({}, { message: '邮箱格式不合法' })
    email: string

    @ApiProperty({ example: '1.jpg', description: '用户头像' })
    @IsOptional()
    avatar?: string

    @ApiProperty({ example: '13788888888', description: '手机号' })
    @IsOptional()
    telephone: string

    @ApiProperty({ example: '235466', description: '验证码' })
    @IsNotEmpty({
        message: '验证码不能为空'
    })
    captcha: string
}

export class CreateUserDto extends UserDto {
    @ApiProperty({ example: '123456', description: '密码' })
    @IsNotEmpty({
        message: '密码不能为空'
    })
    @MinLength(8)
    password: string
}

export class UpdateUserInfoDto extends UserDto {
    @ApiProperty({ example: '1111', description: '用户id' })
    @IsOptional()
    @Type(() => Number)
    @IsInt()
    userId: number
}

export class FrozenUserDto {
    @ApiProperty({ example: '1111', description: '用户id' })
    @IsOptional()
    @Type(() => Number)
    @IsInt()
    userId: number

    @ApiProperty({ example: 'false', description: '是否冻结' })
    @IsNotEmpty({
        message: '不能为空'
    })
    isFrozen: boolean
}

export class DeleteUserDto {
    @ApiProperty({ example: '1111', description: '用户id' })
    @IsNotEmpty({
        message: '用户id不能为空'
    })
    @Type(() => Number)
    @IsInt()
    id: number
}

export class FindManyUserDto extends PaginatedDto { }

export class FindOneUserDto {
    @ApiProperty({ example: '1111', description: '用户id' })
    @IsNotEmpty({
        message: '用户id不能为空'
    })
    @Type(() => Number)
    @IsInt()
    id: number
}

export class RegisterCaptchaDto {
    @ApiProperty({ example: 'coldpants@qq.com', description: '邮箱' })
    @IsNotEmpty({
        message: '邮箱不能为空'
    })
    @IsEmail({}, { message: '邮箱格式不合法' })
    email: string

    @ApiProperty({ example: 'register', description: 'register || findPass' })
    @IsNotEmpty({
        message: '类型不能为空'
    })
    type: string
}

export class UpdateInfoCaptchaDto {
    @ApiProperty({ example: 'coldpants@qq.com', description: '邮箱' })
    @IsNotEmpty({
        message: '邮箱不能为空'
    })
    @IsEmail({}, { message: '邮箱格式不合法' })
    email: string

    @ApiProperty({ example: '100000', description: '用户id' })
    @IsOptional()
    @Type(() => Number)
    @IsInt()
    userId: number
}

export class LoginUserDto {
    @ApiProperty({ example: 'coldpants', description: '用户名' })
    @IsNotEmpty({
        message: '用户名不能为空'
    })
    @MinLength(5)
    @MaxLength(16)
    username: string

    @ApiProperty({ example: '123456', description: '密码' })
    @IsNotEmpty({
        message: '密码不能为空'
    })
    @MinLength(8)
    password: string
}

export class EditUserRoles {
    @ApiProperty({ example: '1111', description: '用户id' })
    @IsNotEmpty({
        message: '用户id不能为空'
    })
    @Type(() => Number)
    @IsInt()
    id: number

    @ApiProperty({ example: [{ id: 1 }], description: '用户角色id数组' })
    @IsNotEmpty({
        message: '用户角色数组不能为空'
    })
    roles: []
}

export class UpdatePass {
    @ApiProperty({ example: 'coldpants@qq.com', description: '邮箱' })
    @IsNotEmpty({
        message: '邮箱不能为空'
    })
    @IsEmail({}, { message: '邮箱格式不合法' })
    email: string

    @ApiProperty({ example: '235466', description: '验证码' })
    @IsNotEmpty({
        message: '验证码不能为空'
    })
    captcha: string

    @ApiProperty({ example: '123456', description: '密码' })
    @IsNotEmpty({
        message: '密码不能为空'
    })
    @MinLength(8)
    password: string
}

